// 导入请求工具类
import request from '@/utils/request'
import {
    useTokenStore
} from '@/stores/token.js'

// 货物列表查询
export const goodsListService = () => {
    // 在pinia中定义的响应式数据，都不需要.value
    // return request.get('/warehouses',{headers:{'token':tokenStore.token}})
    return request.get('/products')
}

// 提供调用添加货物接口的函数
export const goodsAddService = (goodsData) => {
    const params = new URLSearchParams()
    for (let key in goodsData) {
        params.append(key, goodsData[key]);
    }
    return request.post('/product', params)
}

// 货物修改
export const goodsUpdateService = (goodsData) => {
    const requestData = { ...goodsData }; // 创建一个新对象，复制 warehouseData
    const productID = requestData.productID;
    delete requestData.productID; // 从请求数据中删除 warehouseID

    const params = new URLSearchParams()
    for (let key in requestData) {
        params.append(key, requestData[key]);
    }
    return request.put('/product/'+productID, params)
}

// 货物删除
export const goodsDeleteService = (productID) => {
    return request.delete('/product/'+productID)
}

// 入库
export const goodsInService = (goodsData) => {
    const requestData = { ...goodsData }; // 创建一个新对象，复制 warehouseData
    const productID = requestData.productID;
    delete requestData.productID; // 从请求数据中删除 warehouseID

    const params = new URLSearchParams()
    for (let key in requestData) {
        params.append(key, requestData[key]);
    }
    return request.put('/product/inbound/'+productID, params)
}
// 出库
export const goodsOutService = (goodsData) => {
    const requestData = { ...goodsData }; // 创建一个新对象，复制 warehouseData
    const productID = requestData.productID;
    delete requestData.productID; // 从请求数据中删除 warehouseID

    const params = new URLSearchParams()
    for (let key in requestData) {
        params.append(key, requestData[key]);
    }
    return request.put('/product/outbound/'+productID, params)
}

// 货物搜索
export const goodsSearchService = (goodsData) => {
    const requestData = { ...goodsData }; // 创建一个新对象，复制 warehouseData
    const productID = requestData.productID;

    const params = new URLSearchParams()
    for (let key in requestData) {
        params.append(key, requestData[key]);
    }
    return request.get('/product/'+productID, params)
}
